#include "Blocks/PaintedCubeBlock.h"

namespace PocketSurvival
{

    PaintedCubeBlock::PaintedCubeBlock()
    {
        addInheritance(this);
        addInheritance((IPaintableBlock*)this);
    }

    void PaintedCubeBlock::getCreativeValues(std::vector<int32_t> &blockVec)
    {
        blockVec.push_back(Terrain::MakeBlockValue(getIndex(), 0, SetColor(0, -1)));
        for(int32_t index = 0; index < 16; ++index)
        {
            blockVec.push_back(Terrain::MakeBlockValue(getIndex(), 0, SetColor(0, index)));
        }
    }
    void PaintedCubeBlock::getDropValues(int32_t oldValue, int32_t newValue, int32_t toolLevel, std::vector<BlockDropValue> &dropValues)
    {
        int32_t data = Terrain::ExtractData(oldValue);
        if(GetColor(data) != -1)
        {
            if(toolLevel >= RequiredToolLevel)
            {
                dropValues.emplace_back(Terrain::MakeBlockValue(DefaultDropContent, 0, data), (int32_t)DefaultDropCount);
            }
        }
        else
        {
            Block::getDropValues(oldValue, newValue, toolLevel, dropValues);
        }
    }

    int32_t PaintedCubeBlock::getPaintColor(int32_t value)
    {
        return GetColor(Terrain::ExtractData(value));
    }
    int32_t PaintedCubeBlock::paint(int32_t value, int32_t color)
    {
        int32_t data = Terrain::ExtractData(value);
        return Terrain::ReplaceData(value, SetColor(data, color));
    }

} // namespace PocketSurvival
